package weaver.interfaces.cyjt.duss.action;

import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.cyjt.duss.utils.CyjtActionUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2024-03-28
 * @Description: 调用审批结果回传接口推送节点信息
 * @ModifyLog:
 **/
public class WeaSendApprovalBackAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String remark = requestInfo.getRequestManager().getRemark();
        writeLog(">>>>>WeaSendApprovalBackAction>>>>>requestid=" + requestid);
        try {
            RecordSet rs = new RecordSet();
            JSONObject paramJson = new JSONObject();
            rs.executeQuery("select id,spzt from " + tablename + " where requestid=?", requestid);
            rs.next();
            String spzt = Util.null2String(rs.getString("spzt"));
            paramJson.put("requestid", requestid);
            paramJson.put("type", spzt);
            paramJson.put("typeMemo", remark);
            writeLog(">>>>>WeaSendApprovalBackAction>>>>>paramJson=" + paramJson);
            JSONObject resultJson = CyjtActionUtil.sendOKHttpRequest(paramJson.toJSONString());
            writeLog(">>>>>WeaSendApprovalBackAction>>>>>resultJson=" + resultJson);
            String message = Util.null2String(resultJson.getString("message"));
            if ("success".equals(message)) {
                JSONObject dataJson = JSONObject.parseObject(resultJson.getString("data"));
                if (!"200".equals(Util.null2String(dataJson.getString("code")))) {
                    String msg = Util.null2String(dataJson.getString("msg"));
                    requestInfo.getRequestManager().setMessageid("111111");
                    requestInfo.getRequestManager().setMessagecontent(msg);
                    return Action.FAILURE_AND_CONTINUE;
                }
            } else {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent(message);
                return Action.FAILURE_AND_CONTINUE;
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            writeLog(">>>>>WeaZjjhtbsplcCreatejhidAction>>>>>Exception=" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口处理异常,请联系管理员");
            return Action.FAILURE_AND_CONTINUE;
        }
    }


}